#include<bits/stdc++.h>
using namespace std;

class solution{
    private:
        int p[7] = {30,35,15,5,10,20,25};
    public:
        int A(int i,int j){
            if(i==j){
                return 0;
            }
            if(i<j){
                int temp,record = 0xFFFF;
                for(int k=i;k<j;k++){
                    temp = A(i,k)+A(k+1,j)+p[i-1]*p[k]*p[j];
                    if(temp<record){
                        record = temp;
                    }
                }
            }
        }
};

int main(){
    solution a;
    cout<<a.A(1,6);
}